package com.github.cakin.shiro.chapter15.entity;

import java.io.Serializable;

/**
 * @className: User
 * @description: 用户实体
 * @date: 2020/5/19
 * @author: cakin
 */
public class User implements Serializable {
    /**
     * 用户id
     */
    private Long id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 盐
     */
    private String salt;
    /**
     * 是否锁定
     */
    private Boolean locked = Boolean.FALSE;

    public User() {
    }

    public User( String username, String password ) {
        this.username = username;
        this.password = password;
    }

    public Long getId() {
        return id;
    }

    public void setId( Long id ) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername( String username ) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword( String password ) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt( String salt ) {
        this.salt = salt;
    }

    /**
     * 功能描述：真正盐是 用户名+盐
     *
     * @return String
     * @author cakin
     * @date 2020/5/19
     */
    public String getCredentialsSalt() {
        return username + salt;
    }

    public Boolean getLocked() {
        return locked;
    }

    public void setLocked( Boolean locked ) {
        this.locked = locked;
    }

    @Override
    public boolean equals( Object o ) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        User user = (User) o;

        if (id != null ? !id.equals(user.id) : user.id != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "User{"
                + "id=" + id
                + ", username='" + username + '\''
                + ", password='" + password + '\''
                + ", salt='" + salt + '\''
                + ", locked=" + locked
                + '}';
    }
}
